package com.pavan.gps;

import com.pavan.nightgps.R;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

public class GPSLocationActivity extends Activity {
    /** Called when the activity is first created. */
	private DbHelper mDbHelper;
	
    @Override
    public void onCreate(Bundle savedInstanceState)

    {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.progress);
    	mDbHelper = new DbHelper(this);
		mDbHelper.open();
		
    /* Use the LocationManager class to obtain GPS locations */
    	LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    	LocationListener mlocListener = new MyLocationListener();
    	mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    }


    /* Class My Location Listener */

    public class MyLocationListener implements LocationListener

    {

    public void onLocationChanged(Location loc)
    {

    Double lat=loc.getLatitude();
    Double lon=loc.getLongitude();
    String Text = "My current location is: " +"Latitud = " + lat +"Longitud = "+lon;
    Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show();
    String la= lat.toString();
    String lo= lon.toString();
    DbHelper db=new DbHelper(getApplicationContext());
    db.open();
    Boolean check=db.check(la, lo);
    if(check)
    {
    	 
    	Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
		Ringtone r= RingtoneManager.getRingtone(getApplicationContext(), alert);
		r.play();
    }
    else
    {
    	
    }
}
    public void onProviderDisabled(String provider)
    {
    	Toast.makeText( getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT).show();
    }
    public void onProviderEnabled(String provider)
    {
    	Toast.makeText( getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();
    }
    public void onStatusChanged(String provider, int status, Bundle extras)
    {


    }

    }/* End of Class MyLocationListener */
}